#include <stdio.h>
#include <string>
#include <iostream>
#include <exception>

#include <execinfo.h>
#include <signal.h>
#include <stdlib.h>

#include "GenericException.hpp"

GenericException::GenericException(const std::string &Location, int Line, const std::string &Function, const std::string &Text) : Location(Location), Line(Line), Function(Function), Text(Text) {
}

std::string GenericException::GetFullText() const {
	std::stringstream Strm;
	Strm << Location << ":" << Line << " [" << Function << "]: " << Text;
	return Strm.str();
}

std::string GenericException::GetText() const {
	return Text;
}

void GenericException::Terminate() const {
	std::cerr << (*this);
	abort();
}

std::ostream& operator<<(std::ostream &Strm, const GenericException &Obj) {
	Strm << "Exception at " << Obj.Location << ", line " << Obj.Line << std::endl;
	Strm << "     At: " << Obj.Function << std::endl;
	Strm << "     Reason: " << Obj.Text << std::endl;
	return Strm;
}

